

package com.hua.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hua.mapper.AdviceMapper;
import com.hua.pojo.Advice;
import com.hua.pojo.Food;
import com.hua.service.AdviceService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hua
 * @since 2023-12-24
 */
@Service
public class AdviceServiceImpl extends ServiceImpl<AdviceMapper, Advice> implements AdviceService {


    //添加用户建议
    @Override
    public int addUserAdvice(Advice newAdvice) {
        return this.baseMapper.insert(newAdvice);

    }

    //根据饭堂id返回对应的建议，时间从新到旧
    @Override
    public  Map<String, Object> getCanteenAdviceList(int canteenId, int pageNo, int pageSize) {
        //多条件查询
        LambdaQueryWrapper<Advice> wrapper=new LambdaQueryWrapper<>();
        //添加查询条件
        wrapper.eq(Advice::getCanteenId,canteenId);//饭堂id
        wrapper.orderByDesc(Advice::getCreateTime);//时间从新的到旧的


        // 创建分页对象
        Page<Advice> page = new Page<>(pageNo, pageSize);
        // 执行查询并获取结果
        page(page, wrapper); // 使用分页查询方法
        List<Advice> adviceList = page.getRecords();


        // 创建结果 Map 对象，包含总数和数据列表
        Map<String, Object> data = new HashMap<>();
        data.put("total", page.getTotal());
        data.put("rows", adviceList);

        return data;
    }
}
